/*
 * Emitter.h
 *
 *  Created on: Jul 12, 2012
 *      Author: luporini
 */

#ifndef EMITTER_H_
#define EMITTER_H_


#include "Common.h"
#include "Module.h"
#include "WorkerGrid.h"

template <class T, class K >
class Emitter: public Module<T, K> {

private:
	WorkerGrid<T, K> *workerGrid;

public:

	inline Emitter ( WorkerGrid<T, K>* _workerGrid )
	{
		workerGrid = _workerGrid;
	}

	inline ~Emitter() {}


protected:

	void run ()
	{
		int 		size; 			//size of the received block
		int 		counter = 0;	//stream counter
		stream_t 	dest;			//STREAM_A or STREAM_B

		cout << "puppaMELO" << endl;
		while (counter < STREAM_LENGTH) {
			T* block = this->alternative ( &size, &dest );

			if ( dest == STREAM_A )
				workerGrid->scatterRow ( block, size );
			else
				workerGrid->scatterCol ( block, size );

			counter += size;
		}
	}


};

#endif /* EMITTER_H_ */
